<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link rel="stylesheet" href="css/login.css">
    <script src="js/jquery.min.js"></script>
</head>
<body>
<%@include file="header.jsp" %>
<section>
    <div id="register">
        <a href="index.jsp"><img src="images/c4.jpg" id="bg-img"></a>
        <div class="select">
            <div class="tabBox">
                <p id="register-user" class="reg_hide">个人登录</p>
                <a href="" style="position: absolute;right:20px;top:55px;">修改密码</a>
            </div>
            <div class="log_error">
                <label class="login_error"></label>
            </div>
            <div class="reg_user" id="user">
                <div class="reg">
                    <label class="select-country">个人账号:</label>
                    <input type="text" class="field" name="userName" id="username" placeholder="账号" />
                </div>
                <div class="reg">
                    <label class="select-country">密&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;码:</label>
                    <input type="password" class="field" name="userPassword" id="password" placeholder="密码" />
                </div>
                <div class="form-item">
                    <input type="submit" class="fill" id="submit" value="登录">
                </div>
                <div class="readme">
                    <label>
                        <input type="checkbox" id="userCheckbox" class="userCheckbox">
                        <span class="checkbox"></span>
                        <span>我已同意<span onclick="Agreement()">《旗木宠物用户使用协议》</span>和<span
                                onclick="Policy()">《旗木宠物隐私政策》</span></span>
                    </label>
                    <span class="logins">新账号，立即 <a href="register.jsp">注册</a></span>
                </div>
            </div>
        </div>
    </div>
</section>
<%--<%@include file="agree.jsp" %>--%>
<%--<%@include file="secret.jsp" %>--%>
<%@include file="footer.jsp" %>
</body>
</html>
<script src="js/jquery.min.js"></script>
<script>
    const  login_error = $(".login_error");
    $("#submit").click(function (){
        const username = $("#username").val();
        const userPwd = $("#password").val();
        $.ajax({
            type: "POST",
            url: "user/login",
            data:{
                username:username,
                userPwd:userPwd
            },
            success:function (res){
                console.log(res)
                if (res.msg == "success"){
                    localStorage.setItem("userJson",JSON.stringify(res.data));
                    window.location.href = "index.jsp";
                }else if (res.msg == "fail"){
                    login_error.text("账户错误");
                }else if (res.msg == "error"){
                    login_error.text("密码错误");
                }else if (res.msg == "cancel"){
                    login_error.text("账户已注销")
                }
            },
            error:function (){
                alert("error");
            }
        })
    })
</script>